// Copyright (c) 2024-present AI-Labs

// @ ts-nocheck
import { AppPlugin } from "@/plugins/AppPlugin.ts";

/**
 * 插件注册器
 */
export class AppPluginRegistry {
    private plugins: Record<string, AppPlugin[]> = {};

    /**
     * 注册容器插件
     * @param slot 容器插槽名称
     * @param plugin 容器插件
     */
    public registerPlugin(slot: string, plugin: AppPlugin): void {
        if (!this.plugins[slot]) {
            this.plugins[slot] = [];
        }
        this.plugins[slot].push(plugin);
    }

    /**
     * 获取所有注册的容器插件
     */
    public getPlugins(): Record<string, AppPlugin[]> {
        return this.plugins;
    }

    /**
     * 根据名称获取插件
     * @param name 插件名称
     */
    public getPluginByName(name: string): AppPlugin | undefined {
        for (const slot in this.plugins) {
            const plugin = this.plugins[slot].find(plugin => plugin.getName() === name);
            if (plugin) {
                return plugin;
            }
        }
    }
}